CFLAGS += -O3
CFLAGS += -fno-strict-aliasing
CFLAGS += $(INCLUDES) -I.
+
+# Define this to make it possible to run valgrind on code linked with these
+# libraries.
+#CFLAGS += -DVALGRIND -O0 -ggdb3
+
# Get gcc to generate the dependencies for us.
CFLAGS += -Wp,-MD,.$(@F).d
LDFLAGS += -L.
int xc_bvtsched_global_set(int xc_handle,
unsigned long ctx_allow)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_SCHEDCTL;
op.u.schedctl.sched_id = SCHED_BVT;
int xc_bvtsched_global_get(int xc_handle,
unsigned long *ctx_allow)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
int ret;
op.cmd = DOM0_SCHEDCTL;
long long warpl,
long long warpu)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
struct bvt_adjdom *bvtadj = &op.u.adjustdom.u.bvt;
op.cmd = DOM0_ADJUSTDOM;
long long *warpu)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
int ret;
struct bvt_adjdom *adjptr = &op.u.adjustdom.u.bvt;
uint32_t *pdomid)
{
int err;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_CREATEDOMAIN;
op.u.createdomain.domain = (domid_t)*pdomid;
int xc_domain_pause(int xc_handle,
uint32_t domid)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_PAUSEDOMAIN;
op.u.pausedomain.domain = (domid_t)domid;
return do_dom0_op(xc_handle, &op);
int xc_domain_unpause(int xc_handle,
uint32_t domid)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_UNPAUSEDOMAIN;
op.u.unpausedomain.domain = (domid_t)domid;
return do_dom0_op(xc_handle, &op);
int xc_domain_destroy(int xc_handle,
uint32_t domid)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_DESTROYDOMAIN;
op.u.destroydomain.domain = (domid_t)domid;
return do_dom0_op(xc_handle, &op);
int vcpu,
cpumap_t cpumap)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_PINCPUDOMAIN;
op.u.pincpudomain.domain = (domid_t)domid;
op.u.pincpudomain.vcpu = vcpu;
{
unsigned int nr_doms;
uint32_t next_domid = first_domid;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
int rc = 0;
memset(info, 0, max_doms*sizeof(xc_dominfo_t));
xc_domaininfo_t *info)
{
int ret = 0;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
return -1;
vcpu_guest_context_t *ctxt)
{
int rc;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_GETVCPUCONTEXT;
op.u.getvcpucontext.domain = (domid_t)domid;
xc_shadow_control_stats_t *stats )
{
int rc;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_SHADOW_CONTROL;
op.u.shadow_control.domain = (domid_t)domid;
op.u.shadow_control.op = sop;
uint32_t domid,
unsigned int max_memkb)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_SETDOMAINMAXMEM;
op.u.setdomainmaxmem.domain = (domid_t)domid;
op.u.setdomainmaxmem.max_memkb = max_memkb;
int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_MAX_VCPUS;
op.u.max_vcpus.domain = (domid_t)domid;
op.u.max_vcpus.max = max;
int xc_domain_sethandle(int xc_handle, uint32_t domid,
xen_domain_handle_t handle)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_SETDOMAINHANDLE;
op.u.setdomainhandle.domain = (domid_t)domid;
memcpy(op.u.setdomainhandle.handle, handle, sizeof(xen_domain_handle_t));
xc_vcpuinfo_t *info)
{
int rc;
- dom0_op_t op;
-
+ DECLARE_DOM0_OP;
op.cmd = DOM0_GETVCPUINFO;
op.u.getvcpuinfo.domain = (domid_t)domid;
op.u.getvcpuinfo.vcpu = (uint16_t)vcpu;
uint16_t nr_ports,
uint16_t allow_access)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_IOPORT_PERMISSION;
op.u.ioport_permission.domain = (domid_t)domid;
static int do_evtchn_op(int xc_handle, evtchn_op_t *op)
{
int ret = -1;
- privcmd_hypercall_t hypercall;
+ DECLARE_HYPERCALL;
hypercall.op = __HYPERVISOR_event_channel_op;
hypercall.arg[0] = (unsigned long)op;
unsigned long count)
{
int ret = -1;
- privcmd_hypercall_t hypercall;
+ DECLARE_HYPERCALL;
hypercall.op = __HYPERVISOR_grant_table_op;
hypercall.arg[0] = cmd;
unsigned int console_evtchn,
unsigned long *console_mfn)
{
- dom0_op_t launch_op, op;
+ dom0_op_t launch_op;
+ DECLARE_DOM0_OP;
int initrd_fd = -1;
gzFile initrd_gfd = NULL;
int rc, i;
}
}
+#ifdef VALGRIND
+ memset(&st_ctxt, 0, sizeof(st_ctxt));
+#endif
+
if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
{
PERROR("%s: ctxt mlock failed", __func__);
unsigned int store_evtchn, unsigned long *store_mfn,
unsigned int console_evtchn, unsigned long *console_mfn)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
int rc = 1, i, n;
unsigned long mfn, pfn;
unsigned int prev_pc, this_pc;
int clear)
{
int ret;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
char *buffer = *pbuffer;
unsigned int nr_chars = *pnr_chars;
xc_physinfo_t *put_info)
{
int ret;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_PHYSINFO;
op.interface_version = DOM0_INTERFACE_VERSION;
int *sched_id)
{
int ret;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_SCHED_ID;
op.interface_version = DOM0_INTERFACE_VERSION;
}
int xc_perfc_control(int xc_handle,
- uint32_t op,
+ uint32_t opcode,
xc_perfc_desc_t *desc)
{
int rc;
- dom0_op_t dop;
+ DECLARE_DOM0_OP;
- dop.cmd = DOM0_PERFCCONTROL;
- dop.u.perfccontrol.op = op;
- dop.u.perfccontrol.desc = desc;
+ op.cmd = DOM0_PERFCCONTROL;
+ op.u.perfccontrol.op = opcode;
+ op.u.perfccontrol.desc = desc;
- rc = do_dom0_op(xc_handle, &dop);
+ rc = do_dom0_op(xc_handle, &op);
- return (rc == 0) ? dop.u.perfccontrol.nr_counters : rc;
+ return (rc == 0) ? op.u.perfccontrol.nr_counters : rc;
}
long long xc_msr_read(int xc_handle, int cpu_mask, int msr)
{
int rc;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_MSR;
op.u.msr.write = 0;
unsigned int high)
{
int rc;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_MSR;
op.u.msr.write = 1;
int xc_get_pfn_type_batch(int xc_handle,
uint32_t dom, int num, unsigned long *arr)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_GETPAGEFRAMEINFO2;
op.u.getpageframeinfo2.domain = (domid_t)dom;
op.u.getpageframeinfo2.num = num;
unsigned long mfn,
uint32_t dom)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_GETPAGEFRAMEINFO;
op.u.getpageframeinfo.pfn = mfn;
op.u.getpageframeinfo.domain = (domid_t)dom;
unsigned int nr_ops,
domid_t dom)
{
- privcmd_hypercall_t hypercall;
+ DECLARE_HYPERCALL;
long ret = -EINVAL;
hypercall.op = __HYPERVISOR_mmuext_op;
static int flush_mmu_updates(int xc_handle, xc_mmu_t *mmu)
{
int err = 0;
- privcmd_hypercall_t hypercall;
+ DECLARE_HYPERCALL;
if ( mmu->idx == 0 )
return 0;
int cmd,
void *arg)
{
- privcmd_hypercall_t hypercall;
+ DECLARE_HYPERCALL;
struct xen_memory_reservation *reservation = arg;
long ret = -EINVAL;
long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu )
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_GETVCPUINFO;
op.u.getvcpuinfo.domain = (domid_t)domid;
unsigned long *pfn_buf,
unsigned long max_pfns)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
int ret;
op.cmd = DOM0_GETMEMLIST;
op.u.getmemlist.domain = (domid_t)domid;
op.u.getmemlist.max_pfns = max_pfns;
op.u.getmemlist.buffer = pfn_buf;
+#ifdef VALGRIND
+ memset(pfn_buf, 0, max_pfns * sizeof(unsigned long));
+#endif
if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
{
long xc_get_tot_pages(int xc_handle, uint32_t domid)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_GETDOMAININFO;
op.u.getdomaininfo.domain = (domid_t)domid;
return (do_dom0_op(xc_handle, &op) < 0) ?
return -ENOMEM;
}
+#ifdef VALGRIND
+ if (argsize != 0)
+ memset(arg, 0, argsize);
+#endif
+
rc = do_xen_version(xc_handle, cmd, arg);
if ( argsize != 0 )
#include <xen/linux/privcmd.h>
+/* valgrind cannot see when a hypercall has filled in some values. For this
+ reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a
+ call, if using valgrind. */
+#ifdef VALGRIND
+#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall; \
+ memset(&hypercall, 0, sizeof(hypercall))
+#define DECLARE_DOM0_OP dom0_op_t op; memset(&op, 0, sizeof(op))
+#else
+#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
+#define DECLARE_DOM0_OP dom0_op_t op
+#endif
+
+
#define PAGE_SHIFT XC_PAGE_SHIFT
#define PAGE_SIZE (1UL << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))
static inline int do_xen_version(int xc_handle, int cmd, void *dest)
{
- privcmd_hypercall_t hypercall;
+ DECLARE_HYPERCALL;
hypercall.op = __HYPERVISOR_xen_version;
hypercall.arg[0] = (unsigned long) cmd;
static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
{
int ret = -1;
- privcmd_hypercall_t hypercall;
+ DECLARE_HYPERCALL;
op->interface_version = DOM0_INTERFACE_VERSION;
int *status,
int options)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
int retval;
struct timespec ts;
ts.tv_sec = 0;
long eaddr,
long edata)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
int status = 0;
struct gdb_regs pt;
long retval = 0;
int xc_sedf_domain_set(int xc_handle,
uint32_t domid, uint64_t period, uint64_t slice,uint64_t latency, uint16_t extratime,uint16_t weight)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
struct sedf_adjdom *p = &op.u.adjustdom.u.sedf;
op.cmd = DOM0_ADJUSTDOM;
int xc_sedf_domain_get(int xc_handle, uint32_t domid, uint64_t *period, uint64_t *slice, uint64_t* latency, uint16_t* extratime, uint16_t* weight)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
int ret;
struct sedf_adjdom *p = &op.u.adjustdom.u.sedf;
int xc_tbuf_enable(int xc_handle, int enable)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_TBUFCONTROL;
op.interface_version = DOM0_INTERFACE_VERSION;
int xc_tbuf_set_size(int xc_handle, uint32_t size)
{
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_TBUFCONTROL;
op.interface_version = DOM0_INTERFACE_VERSION;
int xc_tbuf_get_size(int xc_handle, uint32_t *size)
{
int rc;
- dom0_op_t op;
+ DECLARE_DOM0_OP;
op.cmd = DOM0_TBUFCONTROL;
op.interface_version = DOM0_INTERFACE_VERSION;
#include <xen/linux/privcmd.h>
#include <xen/memory.h>
+/* valgrind cannot see when a hypercall has filled in some values. For this
+ reason, we must zero the dom0_op_t instance before a call, if using
+ valgrind. */
+#ifdef VALGRIND
+#define DECLARE_DOM0_OP dom0_op_t op; memset(&op, 0, sizeof(op))
+#else
+#define DECLARE_DOM0_OP dom0_op_t op
+#endif
+
+
char *xc_read_kernel_image(const char *filename, unsigned long *size);
unsigned long csum_page (void * page);